<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>charpicker.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_charpicker.js.html">charpicker.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Character Picker widget for picking any Unicode character.
<a name="line17"></a> *
<a name="line18"></a> * @see ../demos/charpicker.html
<a name="line19"></a> */
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.ui.CharPicker&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line24"></a>goog.require(&#39;goog.a11y.aria.State&#39;);
<a name="line25"></a>goog.require(&#39;goog.array&#39;);
<a name="line26"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line27"></a>goog.require(&#39;goog.dom&#39;);
<a name="line28"></a>goog.require(&#39;goog.dom.classlist&#39;);
<a name="line29"></a>goog.require(&#39;goog.events&#39;);
<a name="line30"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line31"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line32"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line33"></a>goog.require(&#39;goog.events.InputHandler&#39;);
<a name="line34"></a>goog.require(&#39;goog.events.KeyCodes&#39;);
<a name="line35"></a>goog.require(&#39;goog.events.KeyHandler&#39;);
<a name="line36"></a>goog.require(&#39;goog.i18n.CharListDecompressor&#39;);
<a name="line37"></a>goog.require(&#39;goog.i18n.uChar&#39;);
<a name="line38"></a>goog.require(&#39;goog.structs.Set&#39;);
<a name="line39"></a>goog.require(&#39;goog.style&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.Button&#39;);
<a name="line41"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line42"></a>goog.require(&#39;goog.ui.ContainerScroller&#39;);
<a name="line43"></a>goog.require(&#39;goog.ui.FlatButtonRenderer&#39;);
<a name="line44"></a>goog.require(&#39;goog.ui.HoverCard&#39;);
<a name="line45"></a>goog.require(&#39;goog.ui.LabelInput&#39;);
<a name="line46"></a>goog.require(&#39;goog.ui.Menu&#39;);
<a name="line47"></a>goog.require(&#39;goog.ui.MenuButton&#39;);
<a name="line48"></a>goog.require(&#39;goog.ui.MenuItem&#39;);
<a name="line49"></a>goog.require(&#39;goog.ui.Tooltip&#39;);
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>/**
<a name="line54"></a> * Character Picker Class. This widget can be used to pick any Unicode
<a name="line55"></a> * character by traversing a category-subcategory structure or by inputing its
<a name="line56"></a> * hex value.
<a name="line57"></a> *
<a name="line58"></a> * See charpicker.html demo for example usage.
<a name="line59"></a> * @param {goog.i18n.CharPickerData} charPickerData Category names and charlist.
<a name="line60"></a> * @param {!goog.i18n.uChar.NameFetcher} charNameFetcher Object which fetches
<a name="line61"></a> *     the names of the characters that are shown in the widget. These names
<a name="line62"></a> *     may be stored locally or come from an external source.
<a name="line63"></a> * @param {Array.&lt;string&gt;=} opt_recents List of characters to be displayed in
<a name="line64"></a> *     resently selected characters area.
<a name="line65"></a> * @param {number=} opt_initCategory Sequence number of initial category.
<a name="line66"></a> * @param {number=} opt_initSubcategory Sequence number of initial subcategory.
<a name="line67"></a> * @param {number=} opt_rowCount Number of rows in the grid.
<a name="line68"></a> * @param {number=} opt_columnCount Number of columns in the grid.
<a name="line69"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line70"></a> * @constructor
<a name="line71"></a> * @extends {goog.ui.Component}
<a name="line72"></a> * @final
<a name="line73"></a> */
<a name="line74"></a>goog.ui.CharPicker = function(charPickerData, charNameFetcher, opt_recents,
<a name="line75"></a>                              opt_initCategory, opt_initSubcategory,
<a name="line76"></a>                              opt_rowCount, opt_columnCount, opt_domHelper) {
<a name="line77"></a>  goog.ui.Component.call(this, opt_domHelper);
<a name="line78"></a>
<a name="line79"></a>  /**
<a name="line80"></a>   * Object used to retrieve character names.
<a name="line81"></a>   * @type {!goog.i18n.uChar.NameFetcher}
<a name="line82"></a>   * @private
<a name="line83"></a>   */
<a name="line84"></a>  this.charNameFetcher_ = charNameFetcher;
<a name="line85"></a>
<a name="line86"></a>  /**
<a name="line87"></a>   * Object containing character lists and category names.
<a name="line88"></a>   * @type {goog.i18n.CharPickerData}
<a name="line89"></a>   * @private
<a name="line90"></a>   */
<a name="line91"></a>  this.data_ = charPickerData;
<a name="line92"></a>
<a name="line93"></a>  /**
<a name="line94"></a>   * The category number to be used on widget init.
<a name="line95"></a>   * @type {number}
<a name="line96"></a>   * @private
<a name="line97"></a>   */
<a name="line98"></a>  this.initCategory_ = opt_initCategory || 0;
<a name="line99"></a>
<a name="line100"></a>  /**
<a name="line101"></a>   * The subcategory number to be used on widget init.
<a name="line102"></a>   * @type {number}
<a name="line103"></a>   * @private
<a name="line104"></a>   */
<a name="line105"></a>  this.initSubcategory_ = opt_initSubcategory || 0;
<a name="line106"></a>
<a name="line107"></a>  /**
<a name="line108"></a>   * Number of columns in the grid.
<a name="line109"></a>   * @type {number}
<a name="line110"></a>   * @private
<a name="line111"></a>   */
<a name="line112"></a>  this.columnCount_ = opt_columnCount || 10;
<a name="line113"></a>
<a name="line114"></a>  /**
<a name="line115"></a>   * Number of entries to be added to the grid.
<a name="line116"></a>   * @type {number}
<a name="line117"></a>   * @private
<a name="line118"></a>   */
<a name="line119"></a>  this.gridsize_ = (opt_rowCount || 10) * this.columnCount_;
<a name="line120"></a>
<a name="line121"></a>  /**
<a name="line122"></a>   * Number of the recently selected characters displayed.
<a name="line123"></a>   * @type {number}
<a name="line124"></a>   * @private
<a name="line125"></a>   */
<a name="line126"></a>  this.recentwidth_ = this.columnCount_ + 1;
<a name="line127"></a>
<a name="line128"></a>  /**
<a name="line129"></a>   * List of recently used characters.
<a name="line130"></a>   * @type {Array.&lt;string&gt;}
<a name="line131"></a>   * @private
<a name="line132"></a>   */
<a name="line133"></a>  this.recents_ = opt_recents || [];
<a name="line134"></a>
<a name="line135"></a>  /**
<a name="line136"></a>   * Handler for events.
<a name="line137"></a>   * @type {goog.events.EventHandler.&lt;!goog.ui.CharPicker&gt;}
<a name="line138"></a>   * @private
<a name="line139"></a>   */
<a name="line140"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line141"></a>
<a name="line142"></a>  /**
<a name="line143"></a>   * Decompressor used to get the list of characters from a base88 encoded
<a name="line144"></a>   * character list.
<a name="line145"></a>   * @type {Object}
<a name="line146"></a>   * @private
<a name="line147"></a>   */
<a name="line148"></a>  this.decompressor_ = new goog.i18n.CharListDecompressor();
<a name="line149"></a>};
<a name="line150"></a>goog.inherits(goog.ui.CharPicker, goog.ui.Component);
<a name="line151"></a>
<a name="line152"></a>
<a name="line153"></a>/**
<a name="line154"></a> * The last selected character.
<a name="line155"></a> * @type {?string}
<a name="line156"></a> * @private
<a name="line157"></a> */
<a name="line158"></a>goog.ui.CharPicker.prototype.selectedChar_ = null;
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Set of formatting characters whose display need to be swapped with nbsp
<a name="line163"></a> * to prevent layout issues.
<a name="line164"></a> * @type {goog.structs.Set}
<a name="line165"></a> * @private
<a name="line166"></a> */
<a name="line167"></a>goog.ui.CharPicker.prototype.layoutAlteringChars_ = null;
<a name="line168"></a>
<a name="line169"></a>
<a name="line170"></a>/**
<a name="line171"></a> * The top category menu.
<a name="line172"></a> * @type {goog.ui.Menu}
<a name="line173"></a> * @private
<a name="line174"></a> */
<a name="line175"></a>goog.ui.CharPicker.prototype.menu_ = null;
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>/**
<a name="line179"></a> * The top category menu button.
<a name="line180"></a> * @type {goog.ui.MenuButton}
<a name="line181"></a> * @private
<a name="line182"></a> */
<a name="line183"></a>goog.ui.CharPicker.prototype.menubutton_ = null;
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * The subcategory menu.
<a name="line188"></a> * @type {goog.ui.Menu}
<a name="line189"></a> * @private
<a name="line190"></a> */
<a name="line191"></a>goog.ui.CharPicker.prototype.submenu_ = null;
<a name="line192"></a>
<a name="line193"></a>
<a name="line194"></a>/**
<a name="line195"></a> * The subcategory menu button.
<a name="line196"></a> * @type {goog.ui.MenuButton}
<a name="line197"></a> * @private
<a name="line198"></a> */
<a name="line199"></a>goog.ui.CharPicker.prototype.submenubutton_ = null;
<a name="line200"></a>
<a name="line201"></a>
<a name="line202"></a>/**
<a name="line203"></a> * The element representing the number of rows visible in the grid.
<a name="line204"></a> * This along with goog.ui.CharPicker.stick_ would help to create a scrollbar
<a name="line205"></a> * of right size.
<a name="line206"></a> * @type {Element}
<a name="line207"></a> * @private
<a name="line208"></a> */
<a name="line209"></a>goog.ui.CharPicker.prototype.stickwrap_ = null;
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * The component containing all the buttons for each character in display.
<a name="line214"></a> * @type {goog.ui.Component}
<a name="line215"></a> * @private
<a name="line216"></a> */
<a name="line217"></a>goog.ui.CharPicker.prototype.grid_ = null;
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * The component used for extra information about the character set displayed.
<a name="line222"></a> * @type {goog.ui.Component}
<a name="line223"></a> * @private
<a name="line224"></a> */
<a name="line225"></a>goog.ui.CharPicker.prototype.notice_ = null;
<a name="line226"></a>
<a name="line227"></a>
<a name="line228"></a>/**
<a name="line229"></a> * Grid displaying recently selected characters.
<a name="line230"></a> * @type {goog.ui.Component}
<a name="line231"></a> * @private
<a name="line232"></a> */
<a name="line233"></a>goog.ui.CharPicker.prototype.recentgrid_ = null;
<a name="line234"></a>
<a name="line235"></a>
<a name="line236"></a>/**
<a name="line237"></a> * Input field for entering the hex value of the character.
<a name="line238"></a> * @type {goog.ui.Component}
<a name="line239"></a> * @private
<a name="line240"></a> */
<a name="line241"></a>goog.ui.CharPicker.prototype.input_ = null;
<a name="line242"></a>
<a name="line243"></a>
<a name="line244"></a>/**
<a name="line245"></a> * OK button for entering hex value of the character.
<a name="line246"></a> * @type {goog.ui.Component}
<a name="line247"></a> * @private
<a name="line248"></a> */
<a name="line249"></a>goog.ui.CharPicker.prototype.okbutton_ = null;
<a name="line250"></a>
<a name="line251"></a>
<a name="line252"></a>/**
<a name="line253"></a> * Element displaying character name in preview.
<a name="line254"></a> * @type {Element}
<a name="line255"></a> * @private
<a name="line256"></a> */
<a name="line257"></a>goog.ui.CharPicker.prototype.charNameEl_ = null;
<a name="line258"></a>
<a name="line259"></a>
<a name="line260"></a>/**
<a name="line261"></a> * Element displaying character in preview.
<a name="line262"></a> * @type {Element}
<a name="line263"></a> * @private
<a name="line264"></a> */
<a name="line265"></a>goog.ui.CharPicker.prototype.zoomEl_ = null;
<a name="line266"></a>
<a name="line267"></a>
<a name="line268"></a>/**
<a name="line269"></a> * Element displaying character number (codepoint) in preview.
<a name="line270"></a> * @type {Element}
<a name="line271"></a> * @private
<a name="line272"></a> */
<a name="line273"></a>goog.ui.CharPicker.prototype.unicodeEl_ = null;
<a name="line274"></a>
<a name="line275"></a>
<a name="line276"></a>/**
<a name="line277"></a> * Hover card for displaying the preview of a character.
<a name="line278"></a> * Preview would contain character in large size and its U+ notation. It would
<a name="line279"></a> * also display the name, if available.
<a name="line280"></a> * @type {goog.ui.HoverCard}
<a name="line281"></a> * @private
<a name="line282"></a> */
<a name="line283"></a>goog.ui.CharPicker.prototype.hc_ = null;
<a name="line284"></a>
<a name="line285"></a>
<a name="line286"></a>/**
<a name="line287"></a> * Gets the last selected character.
<a name="line288"></a> * @return {?string} The last selected character.
<a name="line289"></a> */
<a name="line290"></a>goog.ui.CharPicker.prototype.getSelectedChar = function() {
<a name="line291"></a>  return this.selectedChar_;
<a name="line292"></a>};
<a name="line293"></a>
<a name="line294"></a>
<a name="line295"></a>/**
<a name="line296"></a> * Gets the list of characters user selected recently.
<a name="line297"></a> * @return {Array.&lt;string&gt;} The recent character list.
<a name="line298"></a> */
<a name="line299"></a>goog.ui.CharPicker.prototype.getRecentChars = function() {
<a name="line300"></a>  return this.recents_;
<a name="line301"></a>};
<a name="line302"></a>
<a name="line303"></a>
<a name="line304"></a>/** @override */
<a name="line305"></a>goog.ui.CharPicker.prototype.createDom = function() {
<a name="line306"></a>  goog.ui.CharPicker.superClass_.createDom.call(this);
<a name="line307"></a>
<a name="line308"></a>  this.decorateInternal(this.getDomHelper().createElement(&#39;div&#39;));
<a name="line309"></a>};
<a name="line310"></a>
<a name="line311"></a>
<a name="line312"></a>/** @override */
<a name="line313"></a>goog.ui.CharPicker.prototype.disposeInternal = function() {
<a name="line314"></a>  goog.dispose(this.hc_);
<a name="line315"></a>  this.hc_ = null;
<a name="line316"></a>  goog.dispose(this.eventHandler_);
<a name="line317"></a>  this.eventHandler_ = null;
<a name="line318"></a>  goog.ui.CharPicker.superClass_.disposeInternal.call(this);
<a name="line319"></a>};
<a name="line320"></a>
<a name="line321"></a>
<a name="line322"></a>/** @override */
<a name="line323"></a>goog.ui.CharPicker.prototype.decorateInternal = function(element) {
<a name="line324"></a>  goog.ui.CharPicker.superClass_.decorateInternal.call(this, element);
<a name="line325"></a>
<a name="line326"></a>  // The chars below cause layout disruption or too narrow to hover:
<a name="line327"></a>  // \u0020, \u00AD, \u2000 - \u200f, \u2028 - \u202f, \u3000, \ufeff
<a name="line328"></a>  var chrs = this.decompressor_.toCharList(&#39;:2%C^O80V1H2s2G40Q%s0&#39;);
<a name="line329"></a>  this.layoutAlteringChars_ = new goog.structs.Set(chrs);
<a name="line330"></a>
<a name="line331"></a>  this.menu_ = new goog.ui.Menu(this.getDomHelper());
<a name="line332"></a>
<a name="line333"></a>  var categories = this.data_.categories;
<a name="line334"></a>  for (var i = 0; i &lt; this.data_.categories.length; i++) {
<a name="line335"></a>    this.menu_.addChild(this.createMenuItem_(i, categories[i]), true);
<a name="line336"></a>  }
<a name="line337"></a>
<a name="line338"></a>  this.menubutton_ = new goog.ui.MenuButton(&#39;Category Menu&#39;, this.menu_,
<a name="line339"></a>      /* opt_renderer */ undefined, this.getDomHelper());
<a name="line340"></a>  this.addChild(this.menubutton_, true);
<a name="line341"></a>
<a name="line342"></a>  this.submenu_ = new goog.ui.Menu(this.getDomHelper());
<a name="line343"></a>
<a name="line344"></a>  this.submenubutton_ = new goog.ui.MenuButton(&#39;Subcategory Menu&#39;,
<a name="line345"></a>      this.submenu_, /* opt_renderer */ undefined, this.getDomHelper());
<a name="line346"></a>  this.addChild(this.submenubutton_, true);
<a name="line347"></a>
<a name="line348"></a>  // The containing component for grid component and the scroller.
<a name="line349"></a>  var gridcontainer = new goog.ui.Component(this.getDomHelper());
<a name="line350"></a>  this.addChild(gridcontainer, true);
<a name="line351"></a>
<a name="line352"></a>  var stickwrap = new goog.ui.Component(this.getDomHelper());
<a name="line353"></a>  gridcontainer.addChild(stickwrap, true);
<a name="line354"></a>  this.stickwrap_ = stickwrap.getElement();
<a name="line355"></a>
<a name="line356"></a>  var stick = new goog.ui.Component(this.getDomHelper());
<a name="line357"></a>  stickwrap.addChild(stick, true);
<a name="line358"></a>  this.stick_ = stick.getElement();
<a name="line359"></a>
<a name="line360"></a>  this.grid_ = new goog.ui.Component(this.getDomHelper());
<a name="line361"></a>  gridcontainer.addChild(this.grid_, true);
<a name="line362"></a>
<a name="line363"></a>  this.notice_ = new goog.ui.Component(this.getDomHelper());
<a name="line364"></a>  this.notice_.setElementInternal(this.getDomHelper().createDom(&#39;div&#39;));
<a name="line365"></a>  this.addChild(this.notice_, true);
<a name="line366"></a>
<a name="line367"></a>  // The component used for displaying &#39;Recent Selections&#39; label.
<a name="line368"></a>  /**
<a name="line369"></a>   * @desc The text label above the list of recently selected characters.
<a name="line370"></a>   */
<a name="line371"></a>  var MSG_CHAR_PICKER_RECENT_SELECTIONS = goog.getMsg(&#39;Recent Selections:&#39;);
<a name="line372"></a>  var recenttext = new goog.ui.Component(this.getDomHelper());
<a name="line373"></a>  recenttext.setElementInternal(this.getDomHelper().createDom(&#39;span&#39;, null,
<a name="line374"></a>      MSG_CHAR_PICKER_RECENT_SELECTIONS));
<a name="line375"></a>  this.addChild(recenttext, true);
<a name="line376"></a>
<a name="line377"></a>  this.recentgrid_ = new goog.ui.Component(this.getDomHelper());
<a name="line378"></a>  this.addChild(this.recentgrid_, true);
<a name="line379"></a>
<a name="line380"></a>  // The component used for displaying &#39;U+&#39;.
<a name="line381"></a>  var uplus = new goog.ui.Component(this.getDomHelper());
<a name="line382"></a>  uplus.setElementInternal(this.getDomHelper().createDom(&#39;span&#39;, null, &#39;U+&#39;));
<a name="line383"></a>  this.addChild(uplus, true);
<a name="line384"></a>
<a name="line385"></a>  /**
<a name="line386"></a>   * @desc The text inside the input box to specify the hex code of a character.
<a name="line387"></a>   */
<a name="line388"></a>  var MSG_CHAR_PICKER_HEX_INPUT = goog.getMsg(&#39;Hex Input&#39;);
<a name="line389"></a>  this.input_ = new goog.ui.LabelInput(
<a name="line390"></a>      MSG_CHAR_PICKER_HEX_INPUT, this.getDomHelper());
<a name="line391"></a>  this.addChild(this.input_, true);
<a name="line392"></a>
<a name="line393"></a>  this.okbutton_ = new goog.ui.Button(
<a name="line394"></a>      &#39;OK&#39;, /* opt_renderer */ undefined, this.getDomHelper());
<a name="line395"></a>  this.addChild(this.okbutton_, true);
<a name="line396"></a>  this.okbutton_.setEnabled(false);
<a name="line397"></a>
<a name="line398"></a>  this.zoomEl_ = this.getDomHelper().createDom(&#39;div&#39;,
<a name="line399"></a>      {id: &#39;zoom&#39;, className: goog.getCssName(&#39;goog-char-picker-char-zoom&#39;)});
<a name="line400"></a>
<a name="line401"></a>  this.charNameEl_ = this.getDomHelper().createDom(&#39;div&#39;,
<a name="line402"></a>      {id: &#39;charName&#39;, className: goog.getCssName(&#39;goog-char-picker-name&#39;)});
<a name="line403"></a>
<a name="line404"></a>  this.unicodeEl_ = this.getDomHelper().createDom(&#39;div&#39;,
<a name="line405"></a>      {id: &#39;unicode&#39;, className: goog.getCssName(&#39;goog-char-picker-unicode&#39;)});
<a name="line406"></a>
<a name="line407"></a>  var card = this.getDomHelper().createDom(&#39;div&#39;,
<a name="line408"></a>      {&#39;id&#39;: &#39;preview&#39;},
<a name="line409"></a>      this.zoomEl_, this.charNameEl_, this.unicodeEl_);
<a name="line410"></a>  goog.style.setElementShown(card, false);
<a name="line411"></a>  this.hc_ = new goog.ui.HoverCard({&#39;DIV&#39;: &#39;char&#39;},
<a name="line412"></a>      /* opt_checkDescendants */ undefined, this.getDomHelper());
<a name="line413"></a>  this.hc_.setElement(card);
<a name="line414"></a>  var self = this;
<a name="line415"></a>
<a name="line416"></a>  /**
<a name="line417"></a>   * Function called by hover card just before it is visible to collect data.
<a name="line418"></a>   */
<a name="line419"></a>  function onBeforeShow() {
<a name="line420"></a>    var trigger = self.hc_.getAnchorElement();
<a name="line421"></a>    var ch = self.getChar_(trigger);
<a name="line422"></a>    if (ch) {
<a name="line423"></a>      goog.dom.setTextContent(self.zoomEl_, self.displayChar_(ch));
<a name="line424"></a>      goog.dom.setTextContent(self.unicodeEl_, goog.i18n.uChar.toHexString(ch));
<a name="line425"></a>      // Clear the character name since we don&#39;t want to show old data because
<a name="line426"></a>      // it is retrieved asynchronously and the DOM object is re-used
<a name="line427"></a>      goog.dom.setTextContent(self.charNameEl_, &#39;&#39;);
<a name="line428"></a>      self.charNameFetcher_.getName(ch, function(charName) {
<a name="line429"></a>        if (charName) {
<a name="line430"></a>          goog.dom.setTextContent(self.charNameEl_, charName);
<a name="line431"></a>        }
<a name="line432"></a>      });
<a name="line433"></a>    }
<a name="line434"></a>  }
<a name="line435"></a>
<a name="line436"></a>  goog.events.listen(this.hc_, goog.ui.HoverCard.EventType.BEFORE_SHOW,
<a name="line437"></a>                     onBeforeShow);
<a name="line438"></a>  goog.asserts.assert(element);
<a name="line439"></a>  goog.dom.classlist.add(element, goog.getCssName(&#39;goog-char-picker&#39;));
<a name="line440"></a>  goog.dom.classlist.add(goog.asserts.assert(this.stick_),
<a name="line441"></a>                         goog.getCssName(&#39;goog-stick&#39;));
<a name="line442"></a>  goog.dom.classlist.add(goog.asserts.assert(this.stickwrap_),
<a name="line443"></a>                         goog.getCssName(&#39;goog-stickwrap&#39;));
<a name="line444"></a>  goog.dom.classlist.add(
<a name="line445"></a>      goog.asserts.assert(gridcontainer.getElement()),
<a name="line446"></a>      goog.getCssName(&#39;goog-char-picker-grid-container&#39;));
<a name="line447"></a>  goog.dom.classlist.add(
<a name="line448"></a>      goog.asserts.assert(this.grid_.getElement()),
<a name="line449"></a>      goog.getCssName(&#39;goog-char-picker-grid&#39;));
<a name="line450"></a>  goog.dom.classlist.add(
<a name="line451"></a>      goog.asserts.assert(this.recentgrid_.getElement()),
<a name="line452"></a>      goog.getCssName(&#39;goog-char-picker-grid&#39;));
<a name="line453"></a>  goog.dom.classlist.add(
<a name="line454"></a>      goog.asserts.assert(this.recentgrid_.getElement()),
<a name="line455"></a>      goog.getCssName(&#39;goog-char-picker-recents&#39;));
<a name="line456"></a>
<a name="line457"></a>  goog.dom.classlist.add(
<a name="line458"></a>      goog.asserts.assert(this.notice_.getElement()),
<a name="line459"></a>      goog.getCssName(&#39;goog-char-picker-notice&#39;));
<a name="line460"></a>  goog.dom.classlist.add(
<a name="line461"></a>      goog.asserts.assert(uplus.getElement()),
<a name="line462"></a>      goog.getCssName(&#39;goog-char-picker-uplus&#39;));
<a name="line463"></a>  goog.dom.classlist.add(
<a name="line464"></a>      goog.asserts.assert(this.input_.getElement()),
<a name="line465"></a>      goog.getCssName(&#39;goog-char-picker-input-box&#39;));
<a name="line466"></a>  goog.dom.classlist.add(
<a name="line467"></a>      goog.asserts.assert(this.okbutton_.getElement()),
<a name="line468"></a>      goog.getCssName(&#39;goog-char-picker-okbutton&#39;));
<a name="line469"></a>  goog.dom.classlist.add(
<a name="line470"></a>      goog.asserts.assert(card),
<a name="line471"></a>      goog.getCssName(&#39;goog-char-picker-hovercard&#39;));
<a name="line472"></a>
<a name="line473"></a>  this.hc_.className = goog.getCssName(&#39;goog-char-picker-hovercard&#39;);
<a name="line474"></a>
<a name="line475"></a>  this.grid_.buttoncount = this.gridsize_;
<a name="line476"></a>  this.recentgrid_.buttoncount = this.recentwidth_;
<a name="line477"></a>  this.populateGridWithButtons_(this.grid_);
<a name="line478"></a>  this.populateGridWithButtons_(this.recentgrid_);
<a name="line479"></a>
<a name="line480"></a>  this.updateGrid_(this.recentgrid_, this.recents_);
<a name="line481"></a>  this.setSelectedCategory_(this.initCategory_, this.initSubcategory_);
<a name="line482"></a>  new goog.ui.ContainerScroller(this.menu_);
<a name="line483"></a>  new goog.ui.ContainerScroller(this.submenu_);
<a name="line484"></a>
<a name="line485"></a>  goog.dom.classlist.add(
<a name="line486"></a>      goog.asserts.assert(this.menu_.getElement()),
<a name="line487"></a>      goog.getCssName(&#39;goog-char-picker-menu&#39;));
<a name="line488"></a>  goog.dom.classlist.add(
<a name="line489"></a>      goog.asserts.assert(this.submenu_.getElement()),
<a name="line490"></a>      goog.getCssName(&#39;goog-char-picker-menu&#39;));
<a name="line491"></a>};
<a name="line492"></a>
<a name="line493"></a>
<a name="line494"></a>/** @override */
<a name="line495"></a>goog.ui.CharPicker.prototype.enterDocument = function() {
<a name="line496"></a>  goog.ui.CharPicker.superClass_.enterDocument.call(this);
<a name="line497"></a>  var inputkh = new goog.events.InputHandler(this.input_.getElement());
<a name="line498"></a>  this.keyHandler_ = new goog.events.KeyHandler(this.input_.getElement());
<a name="line499"></a>
<a name="line500"></a>  // Stop the propagation of ACTION events at menu and submenu buttons.
<a name="line501"></a>  // If stopped at capture phase, the button will not be set to normal state.
<a name="line502"></a>  // If not stopped, the user widget will receive the event, which is
<a name="line503"></a>  // undesired. User widget should receive an event only on the character
<a name="line504"></a>  // click.
<a name="line505"></a>  this.eventHandler_.
<a name="line506"></a>      listen(
<a name="line507"></a>          this.menubutton_,
<a name="line508"></a>          goog.ui.Component.EventType.ACTION,
<a name="line509"></a>          goog.events.Event.stopPropagation).
<a name="line510"></a>      listen(
<a name="line511"></a>          this.submenubutton_,
<a name="line512"></a>          goog.ui.Component.EventType.ACTION,
<a name="line513"></a>          goog.events.Event.stopPropagation).
<a name="line514"></a>      listen(
<a name="line515"></a>          this,
<a name="line516"></a>          goog.ui.Component.EventType.ACTION,
<a name="line517"></a>          this.handleSelectedItem_,
<a name="line518"></a>          true).
<a name="line519"></a>      listen(
<a name="line520"></a>          inputkh,
<a name="line521"></a>          goog.events.InputHandler.EventType.INPUT,
<a name="line522"></a>          this.handleInput_).
<a name="line523"></a>      listen(
<a name="line524"></a>          this.keyHandler_,
<a name="line525"></a>          goog.events.KeyHandler.EventType.KEY,
<a name="line526"></a>          this.handleEnter_).
<a name="line527"></a>      listen(
<a name="line528"></a>          this.recentgrid_,
<a name="line529"></a>          goog.ui.Component.EventType.FOCUS,
<a name="line530"></a>          this.handleFocus_).
<a name="line531"></a>      listen(
<a name="line532"></a>          this.grid_,
<a name="line533"></a>          goog.ui.Component.EventType.FOCUS,
<a name="line534"></a>          this.handleFocus_);
<a name="line535"></a>
<a name="line536"></a>  goog.events.listen(this.okbutton_.getElement(),
<a name="line537"></a>      goog.events.EventType.MOUSEDOWN, this.handleOkClick_, true, this);
<a name="line538"></a>
<a name="line539"></a>  goog.events.listen(this.stickwrap_, goog.events.EventType.SCROLL,
<a name="line540"></a>      this.handleScroll_, true, this);
<a name="line541"></a>};
<a name="line542"></a>
<a name="line543"></a>
<a name="line544"></a>/**
<a name="line545"></a> * Handles the button focus by updating the aria label with the character name
<a name="line546"></a> * so it becomes possible to get spoken feedback while tabbing through the
<a name="line547"></a> * visible symbols.
<a name="line548"></a> * @param {goog.events.Event} e The focus event.
<a name="line549"></a> * @private
<a name="line550"></a> */
<a name="line551"></a>goog.ui.CharPicker.prototype.handleFocus_ = function(e) {
<a name="line552"></a>  var button = e.target;
<a name="line553"></a>  var element = button.getElement();
<a name="line554"></a>  var ch = this.getChar_(element);
<a name="line555"></a>
<a name="line556"></a>  // Clear the aria label to avoid speaking the old value in case the button
<a name="line557"></a>  // element has no char attribute or the character name cannot be retrieved.
<a name="line558"></a>  goog.a11y.aria.setState(element, goog.a11y.aria.State.LABEL, &#39;&#39;);
<a name="line559"></a>
<a name="line560"></a>  if (ch) {
<a name="line561"></a>    // This is working with screen readers because the call to getName is
<a name="line562"></a>    // synchronous once the values have been prefetched by the RemoteNameFetcher
<a name="line563"></a>    // and because it is always synchronous when using the LocalNameFetcher.
<a name="line564"></a>    // Also, the special character itself is not used as the label because some
<a name="line565"></a>    // screen readers, notably ChromeVox, are not able to speak them.
<a name="line566"></a>    // TODO(user): Consider changing the NameFetcher API to provide a
<a name="line567"></a>    // method that lets the caller retrieve multiple character names at once
<a name="line568"></a>    // so that this asynchronous gymnastic can be avoided.
<a name="line569"></a>    this.charNameFetcher_.getName(ch, function(charName) {
<a name="line570"></a>      if (charName) {
<a name="line571"></a>        goog.a11y.aria.setState(
<a name="line572"></a>            element, goog.a11y.aria.State.LABEL, charName);
<a name="line573"></a>      }
<a name="line574"></a>    });
<a name="line575"></a>  }
<a name="line576"></a>};
<a name="line577"></a>
<a name="line578"></a>
<a name="line579"></a>/**
<a name="line580"></a> * On scroll, updates the grid with characters correct to the scroll position.
<a name="line581"></a> * @param {goog.events.Event} e Scroll event to handle.
<a name="line582"></a> * @private
<a name="line583"></a> */
<a name="line584"></a>goog.ui.CharPicker.prototype.handleScroll_ = function(e) {
<a name="line585"></a>  var height = e.target.scrollHeight;
<a name="line586"></a>  var top = e.target.scrollTop;
<a name="line587"></a>  var itempos = Math.ceil(top * this.items.length / (this.columnCount_ *
<a name="line588"></a>      height)) * this.columnCount_;
<a name="line589"></a>  if (this.itempos != itempos) {
<a name="line590"></a>    this.itempos = itempos;
<a name="line591"></a>    this.modifyGridWithItems_(this.grid_, this.items, itempos);
<a name="line592"></a>  }
<a name="line593"></a>  e.stopPropagation();
<a name="line594"></a>};
<a name="line595"></a>
<a name="line596"></a>
<a name="line597"></a>/**
<a name="line598"></a> * On a menu click, sets correct character set in the grid; on a grid click
<a name="line599"></a> * accept the character as the selected one and adds to recent selection, if not
<a name="line600"></a> * already present.
<a name="line601"></a> * @param {goog.events.Event} e Event for the click on menus or grid.
<a name="line602"></a> * @private
<a name="line603"></a> */
<a name="line604"></a>goog.ui.CharPicker.prototype.handleSelectedItem_ = function(e) {
<a name="line605"></a>  if (e.target.getParent() == this.menu_) {
<a name="line606"></a>    this.menu_.setVisible(false);
<a name="line607"></a>    this.setSelectedCategory_(e.target.getValue());
<a name="line608"></a>  } else if (e.target.getParent() == this.submenu_) {
<a name="line609"></a>    this.submenu_.setVisible(false);
<a name="line610"></a>    this.setSelectedSubcategory_(e.target.getValue());
<a name="line611"></a>  } else if (e.target.getParent() == this.grid_) {
<a name="line612"></a>    var button = e.target.getElement();
<a name="line613"></a>    this.selectedChar_ = this.getChar_(button);
<a name="line614"></a>    this.updateRecents_(this.selectedChar_);
<a name="line615"></a>  } else if (e.target.getParent() == this.recentgrid_) {
<a name="line616"></a>    this.selectedChar_ = this.getChar_(e.target.getElement());
<a name="line617"></a>  }
<a name="line618"></a>};
<a name="line619"></a>
<a name="line620"></a>
<a name="line621"></a>/**
<a name="line622"></a> * When user types the characters displays the preview. Enables the OK button,
<a name="line623"></a> * if the character is valid.
<a name="line624"></a> * @param {goog.events.Event} e Event for typing in input field.
<a name="line625"></a> * @private
<a name="line626"></a> */
<a name="line627"></a>goog.ui.CharPicker.prototype.handleInput_ = function(e) {
<a name="line628"></a>  var ch = this.getInputChar();
<a name="line629"></a>  if (ch) {
<a name="line630"></a>    goog.dom.setTextContent(this.zoomEl_, ch);
<a name="line631"></a>    goog.dom.setTextContent(this.unicodeEl_, goog.i18n.uChar.toHexString(ch));
<a name="line632"></a>    goog.dom.setTextContent(this.charNameEl_, &#39;&#39;);
<a name="line633"></a>    var coord =
<a name="line634"></a>        new goog.ui.Tooltip.ElementTooltipPosition(this.input_.getElement());
<a name="line635"></a>    this.hc_.setPosition(coord);
<a name="line636"></a>    this.hc_.triggerForElement(this.input_.getElement());
<a name="line637"></a>    this.okbutton_.setEnabled(true);
<a name="line638"></a>  } else {
<a name="line639"></a>    this.hc_.cancelTrigger();
<a name="line640"></a>    this.hc_.setVisible(false);
<a name="line641"></a>    this.okbutton_.setEnabled(false);
<a name="line642"></a>  }
<a name="line643"></a>};
<a name="line644"></a>
<a name="line645"></a>
<a name="line646"></a>/**
<a name="line647"></a> * On OK click accepts the character and updates the recent char list.
<a name="line648"></a> * @param {goog.events.Event=} opt_event Event for click on OK button.
<a name="line649"></a> * @return {boolean} Indicates whether to propagate event.
<a name="line650"></a> * @private
<a name="line651"></a> */
<a name="line652"></a>goog.ui.CharPicker.prototype.handleOkClick_ = function(opt_event) {
<a name="line653"></a>  var ch = this.getInputChar();
<a name="line654"></a>  if (ch &amp;&amp; ch.charCodeAt(0)) {
<a name="line655"></a>    this.selectedChar_ = ch;
<a name="line656"></a>    this.updateRecents_(ch);
<a name="line657"></a>    return true;
<a name="line658"></a>  }
<a name="line659"></a>  return false;
<a name="line660"></a>};
<a name="line661"></a>
<a name="line662"></a>
<a name="line663"></a>/**
<a name="line664"></a> * Behaves exactly like the OK button on Enter key.
<a name="line665"></a> * @param {goog.events.KeyEvent} e Event for enter on the input field.
<a name="line666"></a> * @return {boolean} Indicates whether to propagate event.
<a name="line667"></a> * @private
<a name="line668"></a> */
<a name="line669"></a>goog.ui.CharPicker.prototype.handleEnter_ = function(e) {
<a name="line670"></a>  if (e.keyCode == goog.events.KeyCodes.ENTER) {
<a name="line671"></a>    return this.handleOkClick_() ?
<a name="line672"></a>        this.dispatchEvent(goog.ui.Component.EventType.ACTION) : false;
<a name="line673"></a>  }
<a name="line674"></a>  return false;
<a name="line675"></a>};
<a name="line676"></a>
<a name="line677"></a>
<a name="line678"></a>/**
<a name="line679"></a> * Gets the character from the event target.
<a name="line680"></a> * @param {Element} e Event target containing the &#39;char&#39; attribute.
<a name="line681"></a> * @return {string} The character specified in the event.
<a name="line682"></a> * @private
<a name="line683"></a> */
<a name="line684"></a>goog.ui.CharPicker.prototype.getChar_ = function(e) {
<a name="line685"></a>  return e.getAttribute(&#39;char&#39;);
<a name="line686"></a>};
<a name="line687"></a>
<a name="line688"></a>
<a name="line689"></a>/**
<a name="line690"></a> * Creates a menu entry for either the category listing or subcategory listing.
<a name="line691"></a> * @param {number} id Id to be used for the entry.
<a name="line692"></a> * @param {string} caption Text displayed for the menu item.
<a name="line693"></a> * @return {goog.ui.MenuItem} Menu item to be added to the menu listing.
<a name="line694"></a> * @private
<a name="line695"></a> */
<a name="line696"></a>goog.ui.CharPicker.prototype.createMenuItem_ = function(id, caption) {
<a name="line697"></a>  var item = new goog.ui.MenuItem(caption, /* model */ id, this.getDomHelper());
<a name="line698"></a>  item.setVisible(true);
<a name="line699"></a>  return item;
<a name="line700"></a>};
<a name="line701"></a>
<a name="line702"></a>
<a name="line703"></a>/**
<a name="line704"></a> * Sets the category and updates the submenu items and grid accordingly.
<a name="line705"></a> * @param {number} category Category index used to index the data tables.
<a name="line706"></a> * @param {number=} opt_subcategory Subcategory index used with category index.
<a name="line707"></a> * @private
<a name="line708"></a> */
<a name="line709"></a>goog.ui.CharPicker.prototype.setSelectedCategory_ = function(category,
<a name="line710"></a>                                                             opt_subcategory) {
<a name="line711"></a>  this.category = category;
<a name="line712"></a>  this.menubutton_.setCaption(this.data_.categories[category]);
<a name="line713"></a>  while (this.submenu_.hasChildren()) {
<a name="line714"></a>    this.submenu_.removeChildAt(0, true).dispose();
<a name="line715"></a>  }
<a name="line716"></a>
<a name="line717"></a>  var subcategories = this.data_.subcategories[category];
<a name="line718"></a>  var charList = this.data_.charList[category];
<a name="line719"></a>  for (var i = 0; i &lt; subcategories.length; i++) {
<a name="line720"></a>    var subtitle = charList[i].length == 0;
<a name="line721"></a>    var item = this.createMenuItem_(i, subcategories[i]);
<a name="line722"></a>    this.submenu_.addChild(item, true);
<a name="line723"></a>  }
<a name="line724"></a>  this.setSelectedSubcategory_(opt_subcategory || 0);
<a name="line725"></a>};
<a name="line726"></a>
<a name="line727"></a>
<a name="line728"></a>/**
<a name="line729"></a> * Sets the subcategory and updates the grid accordingly.
<a name="line730"></a> * @param {number} subcategory Sub-category index used to index the data tables.
<a name="line731"></a> * @private
<a name="line732"></a> */
<a name="line733"></a>goog.ui.CharPicker.prototype.setSelectedSubcategory_ = function(subcategory) {
<a name="line734"></a>  var subcategories = this.data_.subcategories;
<a name="line735"></a>  var name = subcategories[this.category][subcategory];
<a name="line736"></a>  this.submenubutton_.setCaption(name);
<a name="line737"></a>  this.setSelectedGrid_(this.category, subcategory);
<a name="line738"></a>};
<a name="line739"></a>
<a name="line740"></a>
<a name="line741"></a>/**
<a name="line742"></a> * Updates the grid according to a given category and subcategory.
<a name="line743"></a> * @param {number} category Index to the category table.
<a name="line744"></a> * @param {number} subcategory Index to the subcategory table.
<a name="line745"></a> * @private
<a name="line746"></a> */
<a name="line747"></a>goog.ui.CharPicker.prototype.setSelectedGrid_ = function(category,
<a name="line748"></a>    subcategory) {
<a name="line749"></a>  var charLists = this.data_.charList;
<a name="line750"></a>  var charListStr = charLists[category][subcategory];
<a name="line751"></a>  var content = this.decompressor_.toCharList(charListStr);
<a name="line752"></a>  this.charNameFetcher_.prefetch(charListStr);
<a name="line753"></a>  this.updateGrid_(this.grid_, content);
<a name="line754"></a>};
<a name="line755"></a>
<a name="line756"></a>
<a name="line757"></a>/**
<a name="line758"></a> * Updates the grid with new character list.
<a name="line759"></a> * @param {goog.ui.Component} grid The grid which is updated with a new set of
<a name="line760"></a> *     characters.
<a name="line761"></a> * @param {Array.&lt;string&gt;} items Characters to be added to the grid.
<a name="line762"></a> * @private
<a name="line763"></a> */
<a name="line764"></a>goog.ui.CharPicker.prototype.updateGrid_ = function(grid, items) {
<a name="line765"></a>  if (grid == this.grid_) {
<a name="line766"></a>    /**
<a name="line767"></a>     * @desc The message used when there are invisible characters like space
<a name="line768"></a>     *     or format control characters.
<a name="line769"></a>     */
<a name="line770"></a>    var MSG_PLEASE_HOVER =
<a name="line771"></a>        goog.getMsg(&#39;Please hover over each cell for the character name.&#39;);
<a name="line772"></a>
<a name="line773"></a>    goog.dom.setTextContent(this.notice_.getElement(),
<a name="line774"></a>        this.charNameFetcher_.isNameAvailable(
<a name="line775"></a>            items[0]) ? MSG_PLEASE_HOVER : &#39;&#39;);
<a name="line776"></a>    this.items = items;
<a name="line777"></a>    if (this.stickwrap_.offsetHeight &gt; 0) {
<a name="line778"></a>      this.stick_.style.height =
<a name="line779"></a>          this.stickwrap_.offsetHeight * items.length / this.gridsize_ + &#39;px&#39;;
<a name="line780"></a>    } else {
<a name="line781"></a>      // This is the last ditch effort if height is not avaialble.
<a name="line782"></a>      // Maximum of 3em is assumed to the the cell height. Extra space after
<a name="line783"></a>      // last character in the grid is OK.
<a name="line784"></a>      this.stick_.style.height = 3 * this.columnCount_ * items.length /
<a name="line785"></a>          this.gridsize_ + &#39;em&#39;;
<a name="line786"></a>    }
<a name="line787"></a>    this.stickwrap_.scrollTop = 0;
<a name="line788"></a>  }
<a name="line789"></a>
<a name="line790"></a>  this.modifyGridWithItems_(grid, items, 0);
<a name="line791"></a>};
<a name="line792"></a>
<a name="line793"></a>
<a name="line794"></a>/**
<a name="line795"></a> * Updates the grid with new character list for a given starting point.
<a name="line796"></a> * @param {goog.ui.Component} grid The grid which is updated with a new set of
<a name="line797"></a> *     characters.
<a name="line798"></a> * @param {Array.&lt;string&gt;} items Characters to be added to the grid.
<a name="line799"></a> * @param {number} start The index from which the characters should be
<a name="line800"></a> *     displayed.
<a name="line801"></a> * @private
<a name="line802"></a> */
<a name="line803"></a>goog.ui.CharPicker.prototype.modifyGridWithItems_ = function(grid, items,
<a name="line804"></a>    start) {
<a name="line805"></a>  for (var buttonpos = 0, itempos = start;
<a name="line806"></a>       buttonpos &lt; grid.buttoncount &amp;&amp; itempos &lt; items.length;
<a name="line807"></a>       buttonpos++, itempos++) {
<a name="line808"></a>    this.modifyCharNode_(grid.getChildAt(buttonpos), items[itempos]);
<a name="line809"></a>  }
<a name="line810"></a>
<a name="line811"></a>  for (; buttonpos &lt; grid.buttoncount; buttonpos++) {
<a name="line812"></a>    grid.getChildAt(buttonpos).setVisible(false);
<a name="line813"></a>  }
<a name="line814"></a>};
<a name="line815"></a>
<a name="line816"></a>
<a name="line817"></a>/**
<a name="line818"></a> * Creates the grid for characters to displayed for selection.
<a name="line819"></a> * @param {goog.ui.Component} grid The grid which is updated with a new set of
<a name="line820"></a> *     characters.
<a name="line821"></a> * @private
<a name="line822"></a> */
<a name="line823"></a>goog.ui.CharPicker.prototype.populateGridWithButtons_ = function(grid) {
<a name="line824"></a>  for (var i = 0; i &lt; grid.buttoncount; i++) {
<a name="line825"></a>    var button = new goog.ui.Button(&#39; &#39;,
<a name="line826"></a>                                    goog.ui.FlatButtonRenderer.getInstance(),
<a name="line827"></a>                                    this.getDomHelper());
<a name="line828"></a>
<a name="line829"></a>    // Dispatch the focus event so we can update the aria description while
<a name="line830"></a>    // the user tabs through the cells.
<a name="line831"></a>    button.setDispatchTransitionEvents(goog.ui.Component.State.FOCUSED, true);
<a name="line832"></a>
<a name="line833"></a>    grid.addChild(button, true);
<a name="line834"></a>    button.setVisible(false);
<a name="line835"></a>
<a name="line836"></a>    var buttonEl = button.getElement();
<a name="line837"></a>    goog.asserts.assert(buttonEl, &#39;The button DOM element cannot be null.&#39;);
<a name="line838"></a>
<a name="line839"></a>    // Override the button role so the user doesn&#39;t hear &quot;button&quot; each time he
<a name="line840"></a>    // tabs through the cells.
<a name="line841"></a>    goog.a11y.aria.removeRole(buttonEl);
<a name="line842"></a>  }
<a name="line843"></a>};
<a name="line844"></a>
<a name="line845"></a>
<a name="line846"></a>/**
<a name="line847"></a> * Updates the grid cell with new character.
<a name="line848"></a> * @param {goog.ui.Component} button This button is proped up for new character.
<a name="line849"></a> * @param {string} ch Character to be displayed by the button.
<a name="line850"></a> * @private
<a name="line851"></a> */
<a name="line852"></a>goog.ui.CharPicker.prototype.modifyCharNode_ = function(button, ch) {
<a name="line853"></a>  var text = this.displayChar_(ch);
<a name="line854"></a>  var buttonEl = button.getElement();
<a name="line855"></a>  goog.dom.setTextContent(buttonEl, text);
<a name="line856"></a>  buttonEl.setAttribute(&#39;char&#39;, ch);
<a name="line857"></a>  button.setVisible(true);
<a name="line858"></a>};
<a name="line859"></a>
<a name="line860"></a>
<a name="line861"></a>/**
<a name="line862"></a> * Adds a given character to the recent character list.
<a name="line863"></a> * @param {string} character Character to be added to the recent list.
<a name="line864"></a> * @private
<a name="line865"></a> */
<a name="line866"></a>goog.ui.CharPicker.prototype.updateRecents_ = function(character) {
<a name="line867"></a>  if (character &amp;&amp; character.charCodeAt(0) &amp;&amp;
<a name="line868"></a>      !goog.array.contains(this.recents_, character)) {
<a name="line869"></a>    this.recents_.unshift(character);
<a name="line870"></a>    if (this.recents_.length &gt; this.recentwidth_) {
<a name="line871"></a>      this.recents_.pop();
<a name="line872"></a>    }
<a name="line873"></a>    this.updateGrid_(this.recentgrid_, this.recents_);
<a name="line874"></a>  }
<a name="line875"></a>};
<a name="line876"></a>
<a name="line877"></a>
<a name="line878"></a>/**
<a name="line879"></a> * Gets the user inputed unicode character.
<a name="line880"></a> * @return {string} Unicode character inputed by user.
<a name="line881"></a> */
<a name="line882"></a>goog.ui.CharPicker.prototype.getInputChar = function() {
<a name="line883"></a>  var text = this.input_.getValue();
<a name="line884"></a>  var code = parseInt(text, 16);
<a name="line885"></a>  return /** @type {string} */ (goog.i18n.uChar.fromCharCode(code));
<a name="line886"></a>};
<a name="line887"></a>
<a name="line888"></a>
<a name="line889"></a>/**
<a name="line890"></a> * Gets the display character for the given character.
<a name="line891"></a> * @param {string} ch Character whose display is fetched.
<a name="line892"></a> * @return {string} The display of the given character.
<a name="line893"></a> * @private
<a name="line894"></a> */
<a name="line895"></a>goog.ui.CharPicker.prototype.displayChar_ = function(ch) {
<a name="line896"></a>  return this.layoutAlteringChars_.contains(ch) ? &#39;\u00A0&#39; : ch;
<a name="line897"></a>};
</pre>


</body>
</html>
